package com.zdkj.subway.stm.util;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zdkj.common.security.util.ObjectUtils;
import com.zdkj.subway.stm.dto.in.QueryContionDTO;
import com.zdkj.subway.stm.dto.in.SwTvmCommonDTO;
import com.zdkj.subway.stm.entity.SwStConductorSettle;
import org.apache.commons.lang3.StringUtils;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

/**
 * @author songtuo
 * @create 2020-03-05 15:44
 * 批量复制默认属性
 */
public class BeanUtilsStm {
    public static <T> void buildProperties(List<T> objs) {
        if (CollectionUtil.isNotEmpty(objs)) {
            SwTvmCommonDTO defaultObj = ObjectUtils.getDefaultObj(SwTvmCommonDTO.class);
            for (T t : objs) {
                BeanUtil.copyProperties(defaultObj, t, CopyOptions.create().setIgnoreNullValue(true));
            }
        }
    }
    /**
     * 时间范围utils 暂时先放到这里 复制时间范围
     */
    public static <T> QueryWrapper<T> addTimeContiontion(T t, QueryContionDTO queryContionDTO,String columnName) {
        QueryWrapper<T> query = Wrappers.query(t);
        if (null != queryContionDTO) {
            LocalDateTime startTime = queryContionDTO.getStartCommonTime();
            if (startTime != null) {
                query.ge(columnName, startTime);
            }
            LocalDateTime endTime = queryContionDTO.getEndCommonTime();
            if (endTime != null) {
                query.le(columnName, endTime);
            }
        }
        return query;
    }

    /**
     * 字符串比较大小
     * @param conductorJobNo1
     * @param conductorJobNo2
     * @return
     */
    public static boolean compareConductorJobNo(String conductorJobNo1,String conductorJobNo2){
        int c=conductorJobNo1.compareTo(conductorJobNo2);
        //大于0交换
        if(c>0){
            return true;
        }
        return false;
    }


    /**
     * BOM编号/工号排序
     * @param bom
     * @return
     */
    public static String bomOrJobNoSort(String bom){
        String[] split = bom.split(",");
        Arrays.sort(split);
        //排序后
        String bomOrJobNoSort = StringUtils.join(split, ",");
        return bomOrJobNoSort;
    }

    /**
     * 字符串去掉空格
     * @param str
     * @return
     */
    public static  String strRemoveBlank(String str){
        String value = str.replaceAll("\\s*", "");
        return value;
    }
}
